package api

import (
	"net/http"
)

var (
	redirectBody = []byte(`<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>30X Moved Permanently</title></head>
<body bgcolor="white">
<h1>30X Moved Permanently</h1>
<p>The requested resource has been assigned a new permanent URI.</p>
<hr/>Powered by 01chain.com</body>
</html>`)
)

type RedirectHandler struct {
	code int
}

func NewRedirectHandler(code int) *RedirectHandler {
	return &RedirectHandler{code: code}
}

func (redirect *RedirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("Location", "https://"+r.Host)
	w.WriteHeader(redirect.code)
	w.Write(redirectBody)

}
